package cn.sendto.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import cn.sendto.model.ClassEntity;
import cn.sendto.model.ScoreEntity;

public class ScoreMapper implements IRowMapper<ScoreEntity> {

	@Override
	public ScoreEntity rowMapper(ResultSet rs) throws SQLException {

		ScoreEntity entity = new ScoreEntity();

		try {
			if(isExistColumn(rs, "scoreid"))
				entity.setScoreId(rs.getInt("scoreid"));
			if(isExistColumn(rs, "score"))
			    entity.setScore(rs.getString("score"));
			if(isExistColumn(rs, "courseid"))
			   entity.setCourseId(rs.getInt("courseid"));
			if(isExistColumn(rs, "studentid"))
			   entity.setStudentId(rs.getString("studentid"));
			if(isExistColumn(rs, "coursename"))
			   entity.setCourseName(rs.getString("coursename"));
			if(isExistColumn(rs, "studentname"))
			    entity.setStudentName(rs.getString("studentname"));
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			System.out.println("数据映射异常"+e.toString());
		}

		return entity;
	}
	 public boolean isExistColumn(ResultSet rs, String columnName) {
	    try {
	        if (rs.findColumn(columnName) > 0 ) {
	            return true;
	        } 
	    }
	    catch (SQLException e) {
	        return false;
	    }
	     
	    return false;
	}



}
